package com.firebird.app.fejpsl.ui.activity.me;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.firebird.app.fejpsl.R;
import com.firebird.app.fejpsl.base.BaseTbActivity;
import com.firebird.app.fejpsl.constant.Constant;

public class PersonInfoActivity extends BaseTbActivity {
    private static final String TEMP_SP="fejpsl_android_file";
    private ImageView myAvatar ;
    private TextView myNiceName,myRegion,myRealName,myBirthday,mySex;
    private TextView myExplicitNiceName;
    private TextView myBindPhone,myAddress;
    private Context mContext;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.me_person_info);
        initView();
        initData();
    }
    private void initData(){
        mContext = getApplicationContext();
        myNiceName = (TextView)findViewById(R.id.mNiceName);
        myRegion=(TextView)findViewById(R.id.mRegion);
        myRealName=(TextView)findViewById(R.id.mRealName);
        myBirthday=(TextView)findViewById(R.id.mBirthday);
        mySex=(TextView)findViewById(R.id.mSex);
        myExplicitNiceName=(TextView)findViewById(R.id.mExplicitNiceName);
        myBindPhone=(TextView)findViewById(R.id.mBindPhone);
        myAddress=(TextView)findViewById(R.id.mAddress);
        myAvatar=(ImageView) findViewById(R.id.iv_avatar);
        SharedPreferences sharedPreferences= getSharedPreferences(TEMP_SP, Context .MODE_PRIVATE);
        String nice_name=sharedPreferences.getString(Constant.NICE_NAME_KEY,"");
        String region=sharedPreferences.getString(Constant.AREA_KEY,"");
        String real_name=sharedPreferences.getString(Constant.REAL_NAME_KEY,"");
        String birthday=sharedPreferences.getString(Constant.BIRTHDAY_KEY,"");
        Integer sex=sharedPreferences.getInt(Constant.SEX_KEY,1);
        Integer explicit_nice_name=sharedPreferences.getInt(Constant.IS_EXPLICIT_KEY,1);
        String bind_phone=sharedPreferences.getString(Constant.PHONE_KEY,"");
        String address=sharedPreferences.getString(Constant.ADDRESS_KEY,"");
        String avatar_base64=sharedPreferences.getString(Constant.AVATAR_KEY,"");
        myNiceName.setText(nice_name);
        myRegion.setText(region);
        myRealName.setText(real_name);
        myBirthday.setText(birthday);
        if(sex==1){
            mySex.setText("男");
        }else{
            mySex.setText("女");
        }
        if(explicit_nice_name==1){
            myExplicitNiceName.setText("使用昵称");
        }else{
            myExplicitNiceName.setText("使用实名");
        }
        myBindPhone.setText(bind_phone);
        myAddress.setText(address);

        byte[] decodedString = Base64.decode(avatar_base64.split(",")[1], Base64.DEFAULT);
        Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
        myAvatar.setImageBitmap(decodedByte);
        //String nicename=Preference(Constant.USERNAME_KEY, "")
    }
    private void initView() {
        Resources r=this.getResources();
        Drawable drawable=r.getDrawable(R.drawable.back);
        drawable.setBounds(0, 0, 120, 120);
        View view= LayoutInflater.from(this).inflate(R.layout.layout_toolbar,null);
        TextView tv_back=(TextView)findViewById(R.id.tv_back);
        tv_back.setCompoundDrawables(drawable, null, null, null);
        setBack();
        String titleName = r.getString(R.string.me_person_info);
        setTitle(titleName);
    }
}
